//
//  ResizeableFormView.h
//  etionUI
//
//  Created by wangjian on 12/26/13.
//  Copyright (c) 2013 GuangZhouXuanWu. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "FreezeFormView.h"

#define FORMVIEW_CELL_MIN_W FORMVIEW_DEF_COL_W
#define FORMVIEW_CELL_MIN_H FORMVIEW_DEF_ROW_H
#define FORMVIEW_CELL_MAX_W 140
#define FORMVIEW_CELL_MAX_H 140

typedef enum
{
    EFormControlViewTypeRow,
    EFormControlViewTypeCol
} EFormControlViewType;

@class CFormResizeCtrlView;
@protocol CFormResizeCtrlViewDelegate <NSObject>

- (void)formResizeCtrlViewSizeChangeBegin:(CFormResizeCtrlView *)ctrlView;
- (void)formResizeCtrlViewSizeChangeEnd:(CFormResizeCtrlView *)ctrlView;
- (void)formResizeCtrlView:(CFormResizeCtrlView *)ctrlView sizeChangeWithOffset:(CGFloat)sizeOffset;

@end

@interface CFormResizeCtrlView : UIView

@property (nonatomic, assign) id<CFormResizeCtrlViewDelegate> delegate;

@property (nonatomic, retain) UIColor *renderColor;

@property (nonatomic, assign) EFormControlViewType type;
@property (nonatomic, assign) CGRect anchorFrame;   //选中的控制cell的frame，用于处理clip区域
@property (nonatomic, assign) CGSize contentSize;   //form view中当前选中行或列的显示大小
@property (nonatomic, assign) CGRect maskFrame;

@property (nonatomic, assign) BOOL isReverse;   //当最右边的列，或最下面的行调整时，为方便操作，进行反向操作

@end

@class CResizeableFormView;
@protocol CResizeableFormViewDelegate <CFreezeFormViewDelegate>

@optional

- (void)resizeableFormViewDidStartResize:(CResizeableFormView *)view;
- (void)resizeableFormViewDidEndResize:(CResizeableFormView *)view;
- (void)resizeableFormViewDidEndScroll:(CResizeableFormView *)view;
- (void)resizeableFormView:(CResizeableFormView *)view rowAtIndex:(NSUInteger)row heightDidChange:(CGFloat)height;
- (void)resizeableFormView:(CResizeableFormView *)view colAtIndex:(NSUInteger)col widthDidChange:(CGFloat)width;

@end

@interface CResizeableFormView : UIView

@property (nonatomic, assign) id<CResizeableFormViewDelegate> delegate;

@property (nonatomic, readonly) CFreezeFormView *formView;

@property (nonatomic, assign) NSUInteger rowNum;
@property (nonatomic, assign) NSUInteger colNum;
@property (nonatomic, assign) NSUInteger freezeTopRowNum;
@property (nonatomic, assign) NSUInteger freezeColNum;
@property (nonatomic, assign) NSUInteger freezeBottomRowNum;

@property (nonatomic, readonly) CGRect contentFrame;
@property (nonatomic, assign, getter = isResizeable) BOOL resizeable;
@property (nonatomic, assign) CFormCellIndex *curSelectedIndex;
/**
 *  指定表格四周的间隙，默认为（10， 10， 10， 10）
 */
@property (nonatomic, assign) UIEdgeInsets edgeInsets;

- (void)reload;

- (void)scrollToIndex:(CFormCellIndex *)index animated:(BOOL)animated;

- (void)fitCellSizeAtIndex:(CFormCellIndex *)index;

// 获取当前表格的内容的高度
- (CGFloat)calculateRealContentHeight;

@end
